package cn.dnui_yxk801.dnuifood_16110100801.Adapter;

import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

import cn.dnui_yxk801.dnuifood_16110100801.R;
import cn.dnui_yxk801.dnuifood_16110100801.bean.CommentsBean;
import cn.dnui_yxk801.dnuifood_16110100801.bean.FoodBean;

public class CommentsAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder>{
    private Context context;
    private List<CommentsBean> datalist;
    private LayoutInflater layoutInflater;
    private static String Baseurl="http://172.24.10.175:8080/foodService/";

    public CommentsAdapter(Context context, List datalist)
    {
        this.context=context;
        this.datalist=datalist;
        layoutInflater=LayoutInflater.from(context);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int i) {
        View v=layoutInflater.from(viewGroup.getContext()).inflate(R.layout.commentsitem,viewGroup,false);
        return new CommentsAdapter.ViewHolder(v);
    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int i) {
        CommentsBean entity=(CommentsBean)datalist.get(i);
        if (entity==null)
            return;
        CommentsAdapter.ViewHolder viewHolder=(CommentsAdapter.ViewHolder)holder;
        viewHolder.username.setText(entity.getUsername());
        viewHolder.content.setText(entity.getContent());
    }

    @Override
    public int getItemCount() {
        return datalist.size();
    }
    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView username,content;
        //ImageView food_pic;


        public ViewHolder(View view) {
            super(view);
            username=(TextView)view.findViewById(R.id.username);
            content=(TextView)view.findViewById(R.id.content);

        }
    }
}
